{%- import "macros/head.html" as head -%}

<!DOCTYPE html>
<html lang="{{ lang }}" prefix="og: https://ogp.me/ns/website#">
  <head>
    {%- block basic_meta -%}
      {{ head::basic_meta() }}
    {%- endblock -%}

    {%- block color_meta -%}
      {{ head::color_meta() }}
    {%- endblock %}

    {%- block ogtitle -%}
      {{ head::ogtitle(tl="") }}
    {%- endblock -%}

    {%- block opengraph_basic_meta -%}
      {{ head::opengraph_basic_meta() }}
    {%- endblock -%}

    {%- block opengraph_optional_meta -%}
      {{ head::opengraph_optional_meta() }}
    {%- endblock -%}

    {%- block favicon -%}
      {{ head::favicon() }}
    {%- endblock -%}

    {%- block manifest -%}
      {{ head::manifest() }}
    {%- endblock -%}

    {%- block feed -%}
      {{ head::feed() }}
    {%- endblock -%}

    {%- block style -%}
      {{ head::style() }}
    {%- endblock -%}

    {%- block base_canonical -%}
      {{ head::base_canonical() }}
    {%- endblock -%}

    {%- block title -%}
      {{ head::head_title(tl="") }}
    {%- endblock -%}
  </head>
  <body>
    <header class="primary-header">
      {%- if config.extra.avatar %}
        <a href="{{ config.base_url | safe }}">
          <picture>
            {%- set meta = get_image_metadata(path=config.extra.avatar) -%}
            <source media="(min-width: 48rem)" srcset="{{ get_url(path=config.extra.avatar) | safe }}" type="image/{{ meta.format | replace(from="svg", to="svg+xml") }}" height=128 width=128>
            <source srcset="{{ get_url(path=config.extra.avatar) | safe }}" type="image/{{ meta.format | replace(from="svg", to="svg+xml") }}" height=80 width=80>
            <img src="{{ get_url(path=config.extra.avatar) | safe }}" alt="the avatar image of {{ config.extra.author }}" height=128 width=128 class="avatar">
          </picture>
        </a>
      {% endif -%}
      <ul role="list">
      {%- block primary_header %}
        {%- if config.extra.author %}
          <li role="listitem"><h1>{{ config.extra.author }}</h1></li>
        {% endif -%}
        {%- if config.extra.username %}
          <li role="listitem"><a href="{{ config.base_url | safe }}">@{{ config.extra.username }}</a></li>
        {% endif -%}
        {%- block header_description %}
          {%- if config.description %}
            <li role="listitem">{{ config.description }}</li>
          {% endif -%}
        {% endblock -%}
        {%- block total_posts %}
          {%- if section.pages and section.pages | length == 1 %}
            <li role="listitem">{{ section.pages | length }} post and counting ...</li>
          {%- elif section.pages and section.pages | length > 1 %}
            <li role="listitem">{{ section.pages | length }} posts and counting ...</li>
          {% endif -%}
        {% endblock -%}
      {% endblock -%}
      </ul>
      {%- block extra_site_header %}
      {% endblock -%}
    </header>
    <nav class="primary-nav">
      <ul role="list">
        {%- block primary_nav %}
          {%- if config.taxonomies %}
            {%- for tax in config.taxonomies %}
              <li role="listitem"><a href="{{ get_url(path=tax.name) }}">{{ tax.name }}</a></li>
              {%- if term.name and tax.feed and config.feed_filename == "atom.xml" %}
                {% set atom_path = term.path ~ config.feed_filename %}
                <li role="listitem"><a href="{{ get_url(path=atom_path) }}">atom feed for #{{ term.name }}</a></li>
              {%- elif term.name and tax.feed and config.feed_filename == "rss.xml" %}
                {% set rss_path = term.path ~ config.feed_filename %}
                <li role="listitem"><a href="{{ get_url(path=rss_path) }}">rss feed for #{{ term.name }}</a></li>
              {%- elif term.name and tax.feed and config.feed_filename %}
                {% set feed_path = term.path ~ config.feed_filename %}
                <li role="listitem"><a href="{{ get_url(path=feed_path) }}">feed for #{{ term.name }}</a></li>
              {%- elif config.generate_feed and config.feed_filename == "rss.xml" %}
                <li role="listitem"><a href="{{ get_url(path=config.feed_filename) }}">rss feed</a></li>
              {%- elif config.generate_feed and config.feed_filename == "atom.xml" %}
                <li role="listitem"><a href="{{ get_url(path=config.feed_filename) }}">atom feed</a></li>
              {%- elif config.generate_feed and config.feed_filename %}
                <li role="listitem"><a href="{{ get_url(path=config.feed_filename) }}">feed</a></li>
              {% endif -%}
            {% endfor -%}
          {% endif -%}
          {%- if config.extra.navbar %}
            {%- for item in config.extra.navbar %}
              {%- if item.name and item.url %}
                {%- if item.url is starting_with("https://") and item.url is not starting_with(config.base_url) %}
                  {%- set newtab_nav = true %}
                {% endif -%}
                <li role="listitem"><a href="{{ item.url | safe }}"{% if newtab_nav %} target="_blank"{% endif %}{% if item.rel or newtab_nav %} rel="{% if item.rel and not newtab_nav %}me{% elif item.rel and newtab_nav %}me {% endif %}{% if newtab_nav %}noopener noreferrer{% endif %}"{% endif %}>{{ item.name }}</a></li>
              {% endif -%}
            {% endfor -%}
          {% endif -%}
        {% endblock -%}
      </ul>
    </nav>
    <main>
      {%- block main %}
      {% endblock -%}
    </main>
    <footer class="primary-footer">
      <ul role="list">
        {%- block site_footer %}
          {%- if config.extra.author %}
            <li role="listitem">&copy;
              <time datetime="{{ now() | date(format="%Y") }}">
                {{ now() | date(format="%Y") }}
              </time> {{ config.extra.author }}
            </li>
          {% endif -%}
          {%- set cl = config.extra.content_license -%}
          {%- set sl = config.extra.source_license -%}
          {%- if cl.spdx and cl.url %}
            {%- if cl.url is starting_with("https://") and cl.url is not starting_with(config.base_url) %}
              {%- set newtab_license = true %}
            {% endif -%}
            <li role="listitem">
              Content <a href="{{ cl.url | safe }}" {% if newtab_license %}target="_blank" rel="noopener noreferrer"{% endif %}>{{ cl.spdx }}</a>
            </li>
          {% endif -%}
          {%- if sl.src_url and sl.src_url is starting_with("https://") and sl.src_url is not starting_with(config.base_url) %}
            {%- set newtab_srcurl = true %}
          {% endif -%}
          {%- if sl.url and sl.url is starting_with("https://") and sl.url is not starting_with(config.base_url) %}
            {%- set newtab_srclicense = true %}
          {% endif -%}
          {%- if sl.spdx and sl.url and sl.src_url %}
            <li role="listitem">
              <a href="{{ sl.src_url | safe }}"{% if newtab_srcurl %} target="_blank" rel="noopener noreferrer"{% endif %}>Source Code</a>
              <a href="{{ sl.url | safe }}"{% if newtab_srclicense %} target="_blank" rel="noopener noreferrer"{% endif %}>{{ sl.spdx }}</a>
            </li>
          {%- elif sl.spdx and sl.url %}
            <li role="listitem">
              Source Code <a href="{{ sl.url | safe }}"{% if newtab_srclicense %} target="_blank" rel="noopener noreferrer"{% endif %}>{{ sl.spdx }}</a>
            </li>
          {% endif -%}
        {% endblock -%}
      </ul>
      {%- block extra_site_footer %}
      {% endblock -%}
    </footer>
  </body>
</html>
